<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>射击成绩管理</title>
<%@ include file="/common/include.jsp"%>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/fancybox/jquery.fancybox-1.3.4.css" media="screen" />
<script language="javascript" type="text/javascript"
	src="${pageContext.request.contextPath}/js/My97DatePicker/WdatePicker.js"></script>
<style>
.tab_c LI {
	PADDING-LEFT: 9px; DISPLAY: inline; FLOAT: left; MARGIN-RIGHT: 3px
}
</style>
<script type="text/javascript">	
$(document).ready(function() {
	var status = "${status}";
	if (status.length > 0) {
		if (status == "1") {
			alert("添加成功!");
			window.location.href="${pageContext.request.contextPath}/page/shootScoreList.jsp";
		} else {
			alert("添加失败!");
		}
	}
	
	$("#select_terminal").fancybox({'width':'50%','height':'70%','type': 'iframe','autocenter':true
		,'onClosed':function(){
			if(window.selectTeminaleNode == null || window.selectTeminaleNode == undefined)
				return;
			$("#dis_tm_nm").val(window.selectTeminaleNode.name);
			$("#dis_tm_cd").val(window.selectTeminaleNode.type + ":" + window.selectTeminaleNode.id);
		}
	});	
	
	// 训练单位级联搜索
	$("#unitByNowGroupId").change(function(){
		var unitByNowGroupId_var = $(this).val();
		if (unitByNowGroupId_var.length > 0)
		{
			$.ajax({
				url:"${pageContext.request.contextPath}/unit/getUnitList/" + unitByNowGroupId_var,
				type: "post",
				contentType: "application/json",
				async: false,
				dataType: "json",
				success: function (data) {
					if (data.length <= 0){
						alert("该大队还没创建分队，请先创建分队");
					}else{
						$("#unitByNewTeamId").empty();
						$("#unitByNewTeamId").append("<option value=\"\">请选择分队</option>");
						$("#unitByNowClassId").empty();
						$("#unitByNowClassId").append("<option value=\"\">请选择班</option>");
						$("#unitByNowClassId").attr("disabled","disabled");
						for (var i=0;i<data.length;i++)
						{
							$("#unitByNewTeamId").append("<option value=\"" + data[i].id + "\">" + data[i].name + "</option>");
						}
						$("#unitByNewTeamId").removeAttr("disabled");
						
						
					}
	    		}
			});
		}
		//重新加载jqgrid
		$("#gridTable").jqGrid('setGridParam',
				{postData:{'unitByNowGroupId':$(this).val(),
					'unitByNewTeamId':'',
					'unitByNowClassId':''
					}}
		).trigger('reloadGrid');
	});
	
	// 训练单位级联搜索
	$("#unitByNewTeamId").change(function(){
		var unitByNewTeamId_var = $(this).val();
		if (unitByNewTeamId_var.length > 0){
			$.ajax({
				url:"${pageContext.request.contextPath}/unit/getUnitList/" + $(this).val(),
				type: "post",
				contentType: "application/json",
				async: false,
				dataType: "json",
				success: function (data) { 
					if (data.length <= 0){
						alert("该分队还没创建班，请先创建班");
					}else{
						$("#unitByNowClassId").empty();
						$("#unitByNowClassId").append("<option value=\"\">请选择班</option>");
						for (var i=0;i<data.length;i++)
						{
							$("#unitByNowClassId").append("<option value=\"" + data[i].id + "\">" + data[i].name + "</option>");
						}
						$("#unitByNowClassId").removeAttr("disabled");
					}
	    		}
			});
		}
		//重新加载jqgrid
		$("#gridTable").jqGrid('setGridParam',
				{postData:{
					'unitByNewTeamId':$(this).val(),
					'unitByNowClassId':''
					}}
		).trigger('reloadGrid');
	});
	
	// 训练单位级联搜索
	$("#unitByNowClassId").change(function(){
		//重新加载jqgrid
		$("#gridTable").jqGrid('setGridParam',
				{postData:{
					'unitByNowClassId':$(this).val()
					}}
		).trigger('reloadGrid');
	});
});
var s=new Array();
$(function()
{
	var temp = "${tmcd}";
	var postData = {unitByNowGroupId:"",unitByNewTeamId:"",unitByNowClassId:""};
	$("#gridTable").jqGrid({
		datatype: "json",
		url:contextPath+'/student/list',
		postData: postData,
		prmNames : {search : "search"}, 
		colNames:["id","姓名","日期","总时间（秒）","短停时间1","短停时间2","短停时间3","跃进距离1","跃进距离2","跃进距离3","固定_命中","运动_命中","机枪_命中","成绩"],
		colModel:[
			{name:'id',index:'id', width:10, hidden:true,
				formatter:function(cellvalue, options, rowObject){
					return "<input  type=\"hidden\" name=\"studentId\" value=\"" + cellvalue + "\"/>";
				}
			},
			{name:'name',index:'student.name',sortable:false,sorttype:"string", width:70,align:"center"},
			{name:'t_trainDate',index:'trainDate',sortable:false,sorttype:"string", width:120,align:"center",
				formatter:function(cellvalue, options, rowObject){
					return "<input  type=\"text\" name=\"trainDate\" onFocus=\"WdatePicker({dateFmt:'yyyy-MM-dd'})\" class=\"Wdate\" style=\"width:100px;\"/>";
				}
			},
			{name:'t_totalTime',index:'totalTime',sortable:false, width:100,align:"center",
				formatter:function(cellvalue, options, rowObject){
					return "<input type=\"text\"  size=\"5\" class=\"input_cj\" name=\"totalTime\" />";
				}	
			},
			{name:'t_stopTime1',index:'stopTime1',sortable:false, width:70,
				formatter:function(cellvalue, options, rowObject){
					return "<input type=\"text\"  size=\"5\" class=\"input_cj\" name=\"stopTime1\" />";
				}
			},
			{name:'t_stopTime2',index:'stopTime2', width:70,sortable:false,align:"center",
				formatter:function(cellvalue, options, rowObject){
					return "<input type=\"text\"  size=\"5\" class=\"input_cj\" name=\"stopTime2\" />";
				}
			},
			{name:'t_stopTime3',index:'stopTime3', width:70,sortable:false,align:"center",
				formatter:function(cellvalue, options, rowObject){
					return "<input type=\"text\"  size=\"5\" class=\"input_cj\" name=\"stopTime3\" />";
				}
			},
			{name:'t_leapDistance1',index:'leapDistance1', width:70,sortable:false,align:"center",
				formatter:function(cellvalue, options, rowObject){
					return "<input type=\"text\"  size=\"5\" class=\"input_cj\" name=\"leapDistance1\" />";
				}
			},
			{name:'t_leapDistance2',index:'leapDistance2', width:70,sortable:false,align:"center",
				formatter:function(cellvalue, options, rowObject){
					return "<input type=\"text\"  size=\"5\" class=\"input_cj\" name=\"leapDistance2\" />";
				}
			},
			{name:'t_leapDistance3',index:'leapDistance3', width:70,sortable:false,
				formatter:function(cellvalue, options, rowObject){
					return "<input type=\"text\"  size=\"5\" class=\"input_cj\" name=\"leapDistance3\" />";
				}
			},
			{name:'t_fixHit',index:'fixHit', width:70,sortable:false,
				formatter:function(cellvalue, options, rowObject){
					return "<input type=\"text\"  size=\"5\" class=\"input_cj\" name=\"fixHit\" />";
				}
			},
			{name:'t_moveHit',index:'moveHit', width:70,sortable:false,
				formatter:function(cellvalue, options, rowObject){
					return "<input type=\"text\"  size=\"5\" class=\"input_cj\" name=\"moveHit\" />";
				}
			},
			{name:'t_gunHit',index:'gunHit', width:70,sortable:false,
				formatter:function(cellvalue, options, rowObject){
					return "<input type=\"text\"  size=\"5\" class=\"input_cj\" name=\"gunHit\" />";
				}	
			},
			{name:'t_score',index:'score',sortable:false, width:70,align:"center",
				formatter:function(cellvalue, options, rowObject){
					var sel_var = "<select name=\"score\" class=\"select_1\" style=\"width: 70px\">"
					sel_var += "<option value=\"1\">优秀</option>";
					sel_var += "<option value=\"2\">良好</option>";
					sel_var += "<option value=\"3\">及格</option>";
					sel_var += "<option value=\"4\">不及格</option>";
					sel_var += "</select>";
					return sel_var;
				}	
			}
		
		
		],
		sortname:'id',
		sortorder:'desc',
		viewrecords:true,
		rowNum:60,
		height:'auto',
		rowList:[10,15,30,60],
		multiselect: true,
		scrollrows: true,
		pager:"#gridPager",
		jsonReader:{
			repeatitems : false
        },
		gridComplete: function(){}
	});
	function formatterLocation(cellvalue, options, rowObject){
		var obj = new Object();
		<c:forEach items="${locationList}" var="code">
			obj["${code.cd}"]="${code.cdnm}";
		</c:forEach>
		return obj[cellvalue];
	}
			
	function formatterOption(cellvalue, options, rowObject){
		var str = '<a href=\"${pageContext.request.contextPath}/ad_place/ad_place.modifyPrepare.do?adplid=' + rowObject.id + '\">修改</a>';
			//+ '&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\"${pageContext.request.contextPath}/order_ad/order_ad.listSchedule.do?actionType=page&adplid=' + rowObject.adplid + '\">安排广告</a>';
		return str;
	}
			
	jQuery.fn.center = function(){
		this.css("position","absolute");
		this.css("top", ( ($(window).height() - this.height() ) / 2+$(window).scrollTop()) + "px");
		this.css("left", (( $(window).width() - this.width() ) / 2+$(window).scrollLeft()) + "px");
		return this;
	};

		var msg="slot_delete@slot_create";
        var slotoptionlist = msg.split('@');
        var slotcreatestate = false;
        /**
        *文件名：ad_place.jsp
        *修改人：林辉
        *日期：2013.3.13
        *描述：广告位的删除操作
        */
        for (var i = 0; i < slotoptionlist.length; i++) {
            if (slotoptionlist[i] == 'slot_delete') {
                jQuery("#gridTable").navGrid('#gridPager', {
                    edit: false,
                    add: false,
                    del: false,
                    search: false,
                    refresh: false
                }).navButtonAdd('#gridPager', {
                    caption: "提交",
                    onClickButton: function() {
                    	$("#adds_form").submit();
                    },
                    position: "last"
                });
            }
            if (slotoptionlist[i] == 'slot_create') {
                slotcreatestate = true;
            }

        }
        if (!slotcreatestate) {
            $('#slotcreatemode').remove();
        }

		var channel='noid';

			if(channel!='noid'&&channel!='')
			{
			jQuery("#channelchange").val(channel);
			$('#channel-noid').addClass('fz_curr');
			$('#channel-noid').siblings().removeClass('fz_curr');
			$('#allchannelname').html("<a href='javascript:getallchannel()'>全部分组</a>");
			$('#slotshowname').html('>  '+$(".fz_list li[id=channel-"+channel+"] a").html());
			}
			var search_word="";

			if (search_word!='')
			{
			$('#search_cd').val(search_word);
			}

			var size_mask="";

			if (size_mask!='')
			{
			$('#sizechange option[value='+size_mask+']').attr('selected',true);
			}
			var type_mask="";

			if (type_mask!='')
			{
			$('#typechange option[value='+type_mask+']').attr('selected',true);
			}
			var staus_mask="4";

			$('#slotstatuslist option[value='+staus_mask+']').attr('selected',true);

			$('#stauschange').val(staus_mask);

			jQuery("#gridTable").jqGrid('navGrid','#gridPager',{edit:false,add:false,del:false,search:false,refresh:false});

			jQuery("#search_cd").keydown(function(e)
			{

			if(e.keyCode==13)
			{
			gridReload();
			}
			});

			$('#search_cd').focus(function()
			{
			var txt_value= $(this).val();
			if(txt_value==this.defaultValue){
			$(this).val("");
			$(this).attr('class',"ss_inp1");
			}

			});
			$('#search_cd').blur(function()
			{

			var txt_value= $(this).val();
			if(txt_value==""){
			$(this).attr('class',"ss_inp");
			$(this).val(this.defaultValue);

			}
			});

			if($("#search_cd").val() == '输入广告位ID或名称关键词' ){
			$('#search_cd').attr('class',"ss_inp");
			}
			else
			{
			$('#search_cd').attr('class',"ss_inp1");
			}
			$('.fz_list li').click(function()
			{

			$(this).addClass('fz_curr');
			$(this).siblings().removeClass('fz_curr');

			});

			$("#gridTable tr:nth-child(2n)").addClass('xxy');
			$('#gridPager').corner("bottom");

			$('#slotnumhelp').html("<span class='statistic'><span class='contextual_shelp'><a href='#'> </a></span></span>");
			$('#slotnumhelp').mousemove(function(){

			$('#key1').show();
			});
			$('#slotnumhelp').mouseleave(function(){

			$('#key1').hide();
			});
			});
			function gridchannelReload(id)
			{
			if($('#searchword').html()!='')
			{
			$('#searchword').html('');
			$("#search_cd").val('输入广告位ID或名称关键词');
			$('#search_cd').attr('class',"ss_inp");
			}
			$('#channelchange').val(id);
			var slot_href=$('#slotlink').val();
			$('#slotcreatemode a').attr('href',slot_href+'&channel='+id);
			$('#allchannelname').html("<a href='javascript:getallchannel()'>全部分组</a>");
			gridReload();
			$('#slotshowname').html(' >  '+$(".fz_list li[id=channel-"+id+"] a").html());
			}
			function getallchannel()
			{
			if($('#searchword').html()!='')
			{
			$('#searchword').html('');
			$("#search_cd").val('输入广告位ID或名称关键词');
			$('#search_cd').attr('class',"ss_inp");
			}
			$('#allchannel').addClass('fz_curr');
			$('#allchannel').siblings().removeClass('fz_curr');
			var slot_href=$('#slotlink').val();
			$('#allchannelname').html("全部分组");
			$('#slotcreatemode a').attr('href',slot_href);
			$('#channelchange').val('');
			$('#slotshowname').html('');


			gridReload();
			}
			
			
/**
*函数名gridReload
*修改人：林辉
*日期：2013.3.13
*描述：增加注释
*/

			function gridReload(state){
			
			var cd_mask = htmlspecialchars(jQuery("#search_cd").val());
			if(cd_mask=='输入学员关键词')cd_mask='';
			if(cd_mask!='')
			{
				$('#searchword').html(' > 关于"'+cd_mask+'"的搜索结果');
				var link=$(".fz_list li[class=fz_curr]").attr('id');
	
				if($('#slotshowname').html().replace(/[ ]/g,'')=='&gt;'+$('#'+link+' a').html())
				{
				var link=$(".fz_list li[class=fz_curr]").attr('id');
				$('#slotshowname').html(" &gt;  <a href=javascript:gridchannelReload("+link.replace('channel-','')+")>"+$('#'+link+' a').html()+"</a>");
	
				}
	
				if($('#allchannelname').html()=='全部分组')
				{
				$('#allchannelname').html("<a href='javascript:getallchannel()'>全部分组</a>");
	
				}
			}

			else
			{
			$('#searchword').html('');
			}

			var status=jQuery("#slotstatuslist").val();
			var type=jQuery("#typechange").val();

			var sno='';//定义一个string，用来存储取得的数据
			
			//用ss来取得选中的表单数据
			var ss = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
			if(state=='delete')
			{
				s=ss;
			}
			else
			{
				s=new Array();
			}

			for(var i=0;i<ss.length;i++)
			{
				if(ss[i]!=undefined)
				{
					var rowData = jQuery("#gridTable").jqGrid("getRowData", ss[i]);
					sno += rowData.adplid + '@';//将ss的数据用@分开，以字符串形式存在sno中
				}

			}
			
			if(state=='delete')
			{
				$.ajax({
					type:'POST',
					url:contextPath+'/ad_place/ad_place.' + state + '.do?actionType=' + state + '&sno=' + sno,
					async:false,
					success:function(msg)
					{
						if(msg.indexOf('guanli_session_timeout_list')!=-1)
						{
							window.location.href='?mo=login&fo=login_timeout';
						}
						else if(msg.indexOf('nocooikelimit')!=-1)
						{
							window.location.href='?mo=login&fo=login_no_limit';
						}
					}
				});
			}
			var betm = $("#fromDate").val();
			var edtm = $("#toDate").val();
			if(betm=='' || edtm==''){alert("开始和结束时间不能为空...");return;}
			
	   		var searchURL = {"plnm":cd_mask,"status":status,"type":type
					,"betm":$("#fromDate").val(),"edtm":$("#toDate").val()}; //现在的值
	   		
			var dis_tm_cd = $("#dis_tm_cd").val();
			if(dis_tm_cd.substring(0,1)=="1"){
				searchURL["dscd"]=dis_tm_cd.substring(2);
			}else{
				searchURL["tmcd"]=dis_tm_cd.substring(2);
			}
			var postData = $("#gridTable").jqGrid("getGridParam", "postData");  //查询出原来的值
	   		$.extend(postData, searchURL);  //替换
	   		
			if(state=='download'){
				var betm = $("#fromDate").val();
				var edtm = $("#toDate").val();
				if(betm=='' || edtm==''){alert("下载报表时开始和结束时间不能为空...");return;}
				
				tool_download(contextPath+'/ad_place/ad_place.exportAdPlaceExcel.do',postData);
			}else{
	    
				jQuery("#gridTable").jqGrid("setGridParam",{
								postData : postData,
								page : 1
							}).trigger("reloadGrid");
	
				}
			}
		function getdeliverydtail(did,num)
		{
				if($('#'+did+'img').attr('src').indexOf('/order/images/ad/jian.gif')!=-1)
					{
						$('#'+did+'img').attr('src','/order/images/ad/jia.gif');
						$('tr[name=trtd'+did+']').remove();
					}
				else if($('#'+did+'img').attr('src').indexOf('/order/images/ad/jia.gif')!=-1)
					{
						$('#'+did+'img').attr('src','/order/images/ad/jian.gif');
						dosomedelivery(did,num);						
					}
			
		}
			
		function in_array(array,string1)
		{
			var  string1 = string1;
			for(i=0;i<array.length;i++)
				{
					if(string1 == array[i])
						{
							return true;
						}
				}
			return false;
		}
</script>
</head>
<body>
	<div style="Z-INDEX: 999; WIDTH: 150px; DISPLAY: none" id=modifypic
		class=succ_box>
		<div class=succ_l>删除成功!</div>
		<div class=succ_r></div>
	</div>
	<div class=wrapper>
		<jsp:include page="/common/header.jsp">
			<jsp:param value="3" name="nav" />
		</jsp:include>
		<div class=content>
			<div class=col_l>
				<div class=l_top></div>
				<div class=l_menu>
					<jsp:include page="/common/l_score_place.jsp">
						<jsp:param value="2" name="nav" />
					</jsp:include>
				</div>
				
				<div class=l_bottom></div>
			</div>
			<div class=col_r>
				<div class="guide blue">
					<span class=left> 当前位置： <a href="${pageContext.request.contextPath }/page/shootScoreList.jsp">射击成绩管理</a> > 添加成绩
					 	<font id=allchannelname style="display:none;">&gt;全部分组</font>
					 	<font id=slotshowname></font>
					 	<font id=searchword style="display:none;"></font> 
					</span> 
					<span class=right>
						
					</span>
				</div>
				<div class=top_title>
					<div class=tab_l></div>
					<div class=tab_c>
						<ul>
							<li>
								训练单位：
                               <select class="select_1" style="width: 129px" id="unitByNowGroupId" name="unitByNowGroupId">
									<option value="">请选择大队</option>
									<c:forEach items="${unitByNowGroupList }" var="unitByNowGroup">
										<option value="${unitByNowGroup.id }">${unitByNowGroup.name }</option>
									</c:forEach>
								</select>
								<select class="select_1" style="width: 129px" id="unitByNewTeamId" name="unitByNewTeamId" disabled="disabled">
									<option value="">请选择分队</option>
								</select>
								<select class="select_1" style="width: 129px" id="unitByNowClassId" name="unitByNowClassId" disabled="disabled">
									<option value="">请选择班</option>
								</select>
							</li>
							<li id=slotcreatemode class="right mar7">
								
							</li>
						</ul>
					</div>
					<div class=tab_r></div>
				</div>
				<form id="adds_form" action="${pageContext.request.contextPath}/shootScore/adds" method="post">
					<div style="width:800px;overflow-x:scroll;overflow-y:hidden;">
					<table id=gridTable class="blue "></table>
					</div>
					<div id=gridPager></div>
				</form>
			</div>
			<div class=clear></div>
			<div style="DISPLAY: none" id=memcache_img></div>
		</div>
		<div class=footer>CopyRight &copy;Research Institute of Computer
			Systems of SCUT. All Rights Reserved</div>
	</div>
	<!--  帮助小提示  -->
<script>
	function showHelp(obj){
	var help = document.getElementById("key"+obj).style.display;
	document.getElementById("key"+obj).style.display="";
	
	} 
	
	function closeHelp(obj){
	var help = document.getElementById("key"+obj).style.display;
	document.getElementById("key"+obj).style.display="none";
	}
</script>
</body>
</html>